<template>
  <div class="goodsContent">
    <ul class="menu">
      <li v-for="item in goods" :key="item.name">
        <span
          ><a :href="`#${item.name}`">{{ item.name }}</a></span
        >
      </li>
    </ul>
    <ol class="list">
      <li v-for="item in goods" :key="item.name">
        <h3 :id="item.name">{{ item.name }}</h3>
        <ul class="info">
          <li v-for="food in item.foods" :key="food.name">
            <div class="box">
              <div class="pic">
                <img :src="food.image" alt="" />
              </div>
              <div class="title">
                <h4>{{ food.name }}</h4>
                <span>￥{{ food.price }}</span>
              </div>
              <btns :item="food" type="0"></btns>
            </div>
          </li>
        </ul>
      </li>
    </ol>
    <div class="shopCar" @click="showCar">
      <span>总价￥{{ getPrice }}</span>
      <span>另需配送费￥4元</span>
      <span class="qian">￥20元起送</span>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
import Btns from "./btns.vue";
export default {
  data() {
    return {};
  },
  components: {
    Btns,
  },
  created() {
    this.getGoods();
    console.log(this.goods);
  },
  computed: {
    ...mapState(["goods", "price", "carList"]),
    getPrice() {
      let num = 0;
      this.carList.forEach((item) => {
        num += item.price * item.count;
      });
      return num;
    },
  },
  methods: {
    ...mapActions(["getGoods"]),
    showCar() {
      this.$store.commit("showCar");
    },
  },
};
</script>

<style lang="less" scoped>
.goodsContent {
  display: flex;
  height: 100%;
  overflow: hidden;

  .menu {
    flex: 0 0 80px;
    overflow-y: scroll;

    li {
      padding: 12px 12px 0 12px;
      height: 42px;
      background: #f3f5f7;
      overflow: hidden;

      span {
        display: block;
        height: 41px;
        font-size: 12px;
        white-space: wrap;
        color: #333;
        border-bottom: 1px solid rgba(7, 17, 27, 0.1);
      }
    }
  }

  .list {
    flex: 1 1 auto;

    overflow-y: scroll;

    h3 {
      border-left: 4px #d9dde1 solid;
      background: #f3f5f7;
      height: 26px;
      line-height: 26px;
      padding-left: 12px;
      color: rgb(147, 153, 159);
      font-weight: 400;
      font-size: 12px;
    }

    .info li {
      padding: 0 18px;
      position: relative;

      .box {
        display: flex;
        padding: 18px 0;
        border-bottom: 1px rgba(1, 17, 27, 0.1) solid;

        .pic img {
          width: 100px;
        }

        .title {
          padding-left: 10px;
        }
      }
    }
  }

  .shopCar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    color: rgba(255, 255, 255, 0.4);
    background-color: rgb(0, 0, 0, 0.2);
    height: 18px;
    z-index: 200;
    font-size: 16px;
    text-align: center;
    display: flex;
    justify-content: space-between;
    padding: 22px 10px 22px 0px;

    .span {
      line-height: 24px;
    }

    .span :nth-child(1) {
      font-size: 16px;
      border-right: 1px rgb(255, 255, 255, 0.1) solid;
    }

    .qian {
      margin-left: -20px;
      font-size: 12px;
      color: rgb(255, 255, 255, 0.4);
      font-weight: 350;
      width: 105px;
    }
  }
}
</style>
